package com.yonyou.pmclouds.productactive.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yonyou.iuap.tenant.sdk.TenantCenter;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.condition.PublicDeployCondition;
import com.yonyou.pmclouds.basecom.conf.ProductActiveProperties;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.exception.ConcurrentOperationException;
import com.yonyou.pmclouds.basecom.util.EncryptUtils;
import com.yonyou.pmclouds.basecom.util.HttpTookit;
import com.yonyou.pmclouds.basecom.view.DisableWrap;
import com.yonyou.pmclouds.productactive.entity.*;
import com.yonyou.pmclouds.productactive.rmiitf.LicenseQuery;
import com.yonyou.pmclouds.productactive.rmiitf.ProductActiveRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@Conditional(PublicDeployCondition.class)
@RequestMapping("/rest/productActive")
@RestController
public class ProductActiveController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private ProductActiveRemoteService productActiveService;
    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private LicenseQuery licenseQuery;
    @Autowired
    private ProductActiveProperties productActiveProperties;
    private ObjectMapper mapper = new ObjectMapper();

    {
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }

    @PostMapping(value = "/business")
    @DisableWrap
    public ResponseEntity<ProductBusinessResponseVO> business(@RequestBody Map<String, Object> requestVO, @RequestHeader("token") String token) throws BusinessException {
        // 这里使用map来接收，避免平台的接口字段变动，导致验签失败
        // 根据现有的需求方案，这里暂时不需要验证请求合法性，因为不进行任何操作，只返回激活地址
        ProductBusinessResponseVO responseVO = new ProductBusinessResponseVO();
        ProductBusinessResponseVO.AppInfo appInfo = new ProductBusinessResponseVO.AppInfo();
        responseVO.setAppInfo(appInfo);
        //  加购续购 1.调用远程存储订单信息
        //  加购续购 2.调用租户中心调整过期日期
        List<Object> orders = (List<Object>) requestVO.get("data");
        responseVO.getAppInfo().setFrontEndUrl("");
        responseVO.getAppInfo().setAdminUrl("");
        responseVO.getAppInfo().setUsername("");
        responseVO.getAppInfo().setPassword("");
        responseVO.getAppInfo().setMessage("");
        responseVO.getAppInfo().setActivateUrl("");
        // 要考虑加购的情况了，所以要校验参数
        boolean legal = ProductActiveUtil.checkTokenOfBuzi(token, productActiveProperties.getResponseSecret(), requestVO);
        if (!legal || CollectionUtils.isEmpty(orders)) {
            responseVO.setResult(300);
        } else {
            Map<String, Object> first = (Map<String, Object>) orders.get(0);
            String action = (String) first.get("action");
            if (StringUtils.isEmpty(action)) {
                responseVO.setResult(300);
            } else {
                String yunType = String.valueOf(first.get("yuntype"));
                if (!"1".equals(yunType)) {
                    // 不是公有云，直接返回发放激活码
                    responseVO.setInstanceId("1");
                    responseVO.setResult(200);
                    responseVO.getAppInfo().setMessage("请使用激活码激活！");
                    responseVO.getAppInfo().setActivateUrl("");
                } else {
                    switch (action) {
                        case "createInstance":
                            responseVO.setInstanceId("1");
                            responseVO.setResult(200);
                            responseVO.getAppInfo().setMessage(productActiveProperties.getActiveMsg());
                            responseVO.getAppInfo().setActivateUrl(productActiveProperties.getActiveRequestUrl());
                            break;
                        case "addInstance":
                            responseVO.setInstanceId((String) first.get("kaiInstanceId"));
                            responseVO.setResult(100);
                            processAddOrder(orders);
                            break;
                        case "renewInstance":
                            responseVO.setInstanceId((String) first.get("kaiInstanceId"));
                            responseVO.setResult(100);
                            processRenewOrder(orders);
                            break;
                    }
                }
            }
        }
        HttpHeaders header = genTokenHeader(responseVO);
        return new ResponseEntity<>(responseVO, header, HttpStatus.OK);
    }

    private HttpHeaders genTokenHeader(ProductBusinessResponseVO responseVO) {
        StringBuilder tokenJson = new StringBuilder();
        tokenJson.append("activateUrl=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getActivateUrl()));
        tokenJson.append("&");
        tokenJson.append("adminUrl=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getAdminUrl()));
        tokenJson.append("&");
        tokenJson.append("frontEndUrl=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getFrontEndUrl()));
        tokenJson.append("&");
        tokenJson.append("message=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getMessage()));
        tokenJson.append("&");
        tokenJson.append("instanceId=").append(StringUtils.trimToEmpty(responseVO.getInstanceId()));
        tokenJson.append("&");
        tokenJson.append("password=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getPassword()));
        tokenJson.append("&");
        tokenJson.append("result=").append(responseVO.getResult());
        tokenJson.append("&");
        tokenJson.append("username=").append(StringUtils.trimToEmpty(responseVO.getAppInfo().getUsername()));
        tokenJson.append("&");
        tokenJson.append("key=").append(productActiveProperties.getResponseSecret());
        HttpHeaders header = new HttpHeaders();
        header.set("token", EncryptUtils.signWithMd5(tokenJson.toString()));
        return header;
    }


    /*
    {
        "sourceID": "APP",
        "eventType": "OPEN_APP_{resCode}",
        "realUserObject": "{  \"tenantId\": \"tttttttt\",\"resCode\": \"hr_clouds\", \"skuId\": \"HR0001\", \"orderId\": \"14601490697582462552\", \"orderBizId\": \"73b1e526-f6eb-40a1-9298-aae34b656668\", \"activationCode\": \"yscff8aeebfb8254931911e17a01da46def\"}"
        }
     */
    @RequestMapping(value = "/active")
    @DisableWrap
    public ProductInitResponseVO active(@RequestBody ProductInitRequestVO requestVO) {
        ProductInitResponseVO responseVO = new ProductInitResponseVO();
        try {
            //不在同一个事务中，需要在异常后表明是那个操作出现的异常
            //查询请求是否已经处理过，并返回剩余需要处理业务数据
            int step = 0;
            requestVO.setRealUserObject(mapper.readValue(requestVO.getUserObject(), ProductInitRequestVO.UserObject.class));
            ProductActiveLogVO logVO = productActiveService.queryLogByID(requestVO.getRealUserObject().getActivationCode());
            Date activeDate = new Date(System.currentTimeMillis());
            Calendar cal = Calendar.getInstance();
            activeDate = toDateBegin(activeDate, cal);
            if (logVO != null) {
                step = logVO.getStep();
                activeDate = logVO.getActiveDate();
            } else {
                logVO = new ProductActiveLogVO();
                logVO.setActiveId(requestVO.getRealUserObject().getActivationCode());
                logVO.setActiveDate(activeDate);
            }
            // 查询激活信息
            ActiveQueryResultVO activeInfo = queryActiveInfo(requestVO);
            if (activeInfo == null) {
                responseVO.setSuccess(false);
            } else if (logVO.getPkActiveLog() == null && activeInfo.getStatus() != 100) {
                // 系统没有日志，激活码不可用，说明接收到了重复使用的激活码
                responseVO.setSuccess(false);
            } else {
                // 注意这里switch没有break,一定没有break
                switch (step) {
                    case 0:
                        try {
                            logVO = productActiveService.saveProductActive(requestVO, activeInfo.getData(), activeDate);
                        } catch (ConcurrentOperationException e) {
                            // 发生了并发异常，说明系统系统正在初始化，就不要往下走了，等初始化完了，他们再调用就会没问题
                            responseVO.setSuccess(false);
                            break;
                        } catch (Exception e) {
                            log.error("租户激活：初始化失败{},{}", requestVO.getRealUserObject().getTenantId(), e);
                            // 失败了先让系统完成下单，后续人工介入
                            logVO.setFailedStep("0,");
                            logVO.setLogContent(requestVO.getUserObject());
                            logVO.setStep(1);
                            productActiveService.updateStep(logVO);
                        }
                    case 1:
                        try {
                            callbackTenantCenter(requestVO, activeInfo, activeDate);
                        } catch (Exception e) {
                            log.error("租户激活：回调租户中心失败{},{}", requestVO.getRealUserObject().getTenantId(), e);
                            logVO.setFailedStep(StringUtils.trimToEmpty(logVO.getFailedStep()) + "1,");
                            //保存日志
                            logVO.setStep(2);
                            productActiveService.updateStep(logVO);
                        }
                    case 2:
                        try {
                            callBusinessServices(requestVO);
                        } catch (Exception e) {
                            log.error("租户激活：回调商务系统失败{},{}", requestVO.getRealUserObject().getTenantId(), e);
                            logVO.setFailedStep(StringUtils.trimToEmpty(logVO.getFailedStep()) + "2,");
                            //保存日志
                            logVO.setStep(3);
                            productActiveService.updateStep(logVO);
                        }
                        responseVO.setSuccess(true);
                    default:
                }
            }
        } catch (Exception e) {
            responseVO.setSuccess(false);
        }
        return responseVO;
    }

    @RequestMapping(value = "/activePersonal")
    @DisableWrap
    public ProductInitResponseVO activePersonal(@RequestBody ProductInitRequestVO requestVO) {
        ProductInitResponseVO responseVO = new ProductInitResponseVO();
        try {
            //不在同一个事务中，需要在异常后表明是那个操作出现的异常
            //查询请求是否已经处理过，并返回剩余需要处理业务数据
            requestVO.setRealUserObject(mapper.readValue(requestVO.getUserObject(), ProductInitRequestVO.UserObject.class));
            String tenantId = requestVO.getRealUserObject().getTenantId();
            String resCode = requestVO.getRealUserObject().getResCode();

            JSONObject json = new JSONObject();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            json.put("tenantId", tenantId);
            json.put("resCode", resCode);
            json.put("beginDate", formatter.format(formatter.parse(requestVO.getStartDate())));
            json.put("endDate", formatter.format(formatter.parse(requestVO.getEndDate())));
            JSONArray jsonArray = new JSONArray();
            jsonArray.add(json);
            String stringBathOpenApp = TenantCenter.StringBathOpenApp(jsonArray.toString());

            log.error("私有云开通结果："+stringBathOpenApp);

            if(requestVO.getInitData() == 1){
                productActiveService.insertScriptAndPrint(tenantId, resCode);
            }
            responseVO.setSuccess(true);
        } catch (Exception e) {
            log.error("私有云开通异常："+e.getMessage(),e);
            responseVO.setSuccess(false);
        }
        return responseVO;
    }

    private Date toDateBegin(Date activeDate, Calendar cal) {
        cal.setTime(activeDate);
        cal.set(Calendar.HOUR, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        activeDate = cal.getTime();
        return activeDate;
    }

    //调用租户中心代码回写生效日期
    private void callbackTenantCenter(ProductInitRequestVO requestVO, ActiveQueryResultVO activeInfo, Date activeDate) {
        int lease = 0;
        ActiveInfoVO activeInfoVO = null;
        for (int i = 0; i < activeInfo.getData().length; i++) {
            // 判断用户的产品id
            if (activeInfo.getData()[i].getProductId().equals(productActiveProperties.getAppBuziId())) {
                lease = activeInfo.getData()[i].getLease();
                activeInfoVO = activeInfo.getData()[i];
            }
        }
        if (lease <= 0) {
            return;
        }
        // 根据租期确认
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(activeDate);
        calendar.add(Calendar.MONTH, lease);
        // 获取当前日期的人
        writeTenantTimeAndCount(requestVO.getRealUserObject().getTenantId(), activeDate, calendar.getTime(), activeInfoVO.getAccountQuantity());

    }

    private void writeTenantTimeAndCount(String tenantId, Date start, Date end, int userCount) {
        JSONObject json = new JSONObject();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        json.put("tenantId", tenantId);
        json.put("resCode", ApplicationConsts.APPLICATION_ID);
        json.put("beginDate", formatter.format(start));
        json.put("endDate", formatter.format(end));
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(json);
        String stringBathOpenApp = TenantCenter.StringBathOpenApp(jsonArray.toString());
        // TODO change to user count ，目前存在问题，多次调用时间不更新
//        TenantCenter.addAndActiveAndAuthNum(tenantId, ApplicationConsts.APPLICATION_ID, null, formatter.format(end), userCount);
    }

    private void callBusinessServices(ProductInitRequestVO requestVO) throws BusinessException {
        JSONObject params = new JSONObject();
        params.put("activationCode", requestVO.getRealUserObject().getActivationCode());
        params.put("action", "activate");
        params.put("instanceId", requestVO.getRealUserObject().getTenantId());
        params.put("tenantId", requestVO.getRealUserObject().getTenantId());
        StringBuilder tokenString = new StringBuilder();
        tokenString.append("action=").append("activate");
        tokenString.append("&");
        tokenString.append("activationCode=").append(requestVO.getRealUserObject().getActivationCode());
        tokenString.append("&");
        tokenString.append("instanceId=").append(requestVO.getRealUserObject().getTenantId());
        tokenString.append("&");
        tokenString.append("tenantId=").append(requestVO.getRealUserObject().getTenantId());
        tokenString.append("&");
        tokenString.append("key=").append(productActiveProperties.getRequestSecret());
        Map<String, String> header = new HashMap<>(1);
        header.put("token", EncryptUtils.signWithMd5(tokenString.toString()));
        String result = null;
        int retry = 0;
        do {
            result = HttpTookit.doPostWithJson(productActiveProperties.getActiveUrl(), params.toString(), header);
            retry++;
        } while (result == null && retry < 3);
        try {
            if (StringUtils.isEmpty(result)) {
                throw new BusinessException("激活失败！");
            }
            ActiveQueryResultVO resultVO = mapper.readValue(result, ActiveQueryResultVO.class);
            if (resultVO.getStatus() != 100) {
                throw new BusinessException("激活失败！");
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            throw new BusinessException("获取激活信息失败!");
        }
    }

    /**
     * {"status":"102","msg":"激活码已使用","data":[{"action":"createInstance","kaiInstanceId":"","fromtype":"55","yuntype":"1","yonyouUid":"163662","orderBizId":"19906","orderId":"XK021241","orderCid":"19906","productId":"596","productName":"工程现场","skuId":0,"accountQuantity":"10","lease":"12","email":"zhaocqa@yonyou.com","mobile":"18210611689","companyName":"zhao_pmgcr","companyShortName":"工程云测试公司"},{"action":"createInstance","kaiInstanceId":"","fromtype":"55","yuntype":"1","yonyouUid":"163662","orderBizId":"19907","orderId":"XK021241","orderCid":"19907","productId":"597","productName":"存储空间","skuId":0,"accountQuantity":"10","lease":"0","email":"zhaocqa@yonyou.com","mobile":"18210611689","companyName":"zhao_pmgcr","companyShortName":"工程云测试公司"},{"action":"createInstance","kaiInstanceId":"","fromtype":"55","yuntype":"1","yonyouUid":"163662","orderBizId":"19908","orderId":"XK021241","orderCid":"19908","productId":"598","productName":"培训实施服务费(驻场)","skuId":0,"accountQuantity":"10","lease":"0","email":"zhaocqa@yonyou.com","mobile":"18210611689","companyName":"zhao_pmgcr","companyShortName":"工程云测试公司"}]}
     */
    private ActiveQueryResultVO queryActiveInfo(ProductInitRequestVO requestVO) throws BusinessException {
        JSONObject params = new JSONObject();
        params.put("activationCode", requestVO.getRealUserObject().getActivationCode());
        params.put("action", "query");
        params.put("instanceId", requestVO.getRealUserObject().getTenantId());
        params.put("tenantId", requestVO.getRealUserObject().getTenantId());
        StringBuilder tokenString = new StringBuilder();
        tokenString.append("action=").append("query");
        tokenString.append("&");
        tokenString.append("activationCode=").append(requestVO.getRealUserObject().getActivationCode());
        tokenString.append("&");
        tokenString.append("instanceId=").append(requestVO.getRealUserObject().getTenantId());
        tokenString.append("&");
        tokenString.append("tenantId=").append(requestVO.getRealUserObject().getTenantId());
        tokenString.append("&");
        //  需要替换key
        tokenString.append("key=").append(productActiveProperties.getRequestSecret());
        Map<String, String> header = new HashMap<>(1);
        header.put("token", EncryptUtils.signWithMd5(tokenString.toString()));
        int retry = 0;
        String result = null;
        do {
            result = HttpTookit.doPostWithJson(productActiveProperties.getActiveUrl(), params.toString(), header);
            retry++;
        } while (result == null && retry < 3);
        try {
            if (StringUtils.isEmpty(result)) {
                return null;
            }
            return mapper.readValue(result, ActiveQueryResultVO.class);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            throw new BusinessException("获取激活信息失败!");
        }

    }

    private void processAddOrder(List<Object> orders) throws BusinessException {
        Map<String, Object> first = (Map<String, Object>) orders.get(0);
        ProductActiveLogVO logVO = productActiveService.queryLogByID((String) first.get("orderId"));
        Date activeDate = new Date();
        if (logVO != null) {
            activeDate = logVO.getActiveDate();
        } else {
            logVO = new ProductActiveLogVO();
            logVO.setActiveId((String) first.get("orderId"));
            logVO.setActiveDate(activeDate);
        }
        int step = logVO.getStep();
        switch (step) {
            case 0:
                try {
                    List<ActiveInfoVO> infos = transActiveInfoVOS(orders);
                    logVO = productActiveService.saveProductAdd(infos.toArray(new ActiveInfoVO[infos.size()]));
                } catch (Exception e) {
                    logVO.setFailedStep("0,");
                    logVO.setStep(1);
                    productActiveService.updateStep(logVO);
                }
            case 1:
                //  发给租户中心，调整授权时间
                try {
                    int lease = 0;
                    String tenantId = null;
                    String startTime = null;
                    for (Object order1 : orders) {
                        // 判断用户的产品id
                        Map<String, Object> order = (Map<String, Object>) order1;
                        if (order.get("productId").equals(productActiveProperties.getAppBuziId())) {
                            lease = Integer.valueOf(String.valueOf(order.get("lease")));
                            tenantId = String.valueOf(order.get("kaiInstanceId"));
                            startTime = String.valueOf(order.get("start_time"));
                            break;
                        }
                    }
                    if (lease > 0) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        Date start = format.parse(startTime);
                        EffectBuziInfoVO effectInfo = licenseQuery.queryEffectUserOfTenant(tenantId, start);
                        Date effectStart = effectInfo.getActiveDate();
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(start);
                        cal.add(Calendar.MONTH, lease);
                        // 加购人数在生效日期的时候再调整
                        int maxUserCountOfTenant = licenseQuery.getMaxUserCountOfTenant(tenantId, new Date());
                        writeTenantTimeAndCount(tenantId, effectStart, cal.getTime(), maxUserCountOfTenant);
                    }
                } catch (Exception e) {
                    logVO.setFailedStep(StringUtils.trimToEmpty(logVO.getFailedStep()) + "2,");
                    logVO.setStep(2);
                    productActiveService.updateStep(logVO);
                }
        }
    }

    private void processRenewOrder(List<Object> orders) throws BusinessException {
        Map<String, Object> first = (Map<String, Object>) orders.get(0);
        ProductActiveLogVO logVO = productActiveService.queryLogByID((String) first.get("orderId"));
        Date activeDate = new Date(System.currentTimeMillis());
        if (logVO != null) {
            activeDate = logVO.getActiveDate();
        } else {
            logVO = new ProductActiveLogVO();
            logVO.setActiveId((String) first.get("orderId"));
            logVO.setActiveDate(activeDate);
        }
        int step = logVO.getStep();
        switch (step) {
            case 0:
                try {
                    List<ActiveInfoVO> infos = transActiveInfoVOS(orders);
                    productActiveService.saveProductRenew(infos.toArray(new ActiveInfoVO[infos.size()]));
                } catch (Exception e) {
                    logVO.setFailedStep("0,");
                    logVO.setStep(1);
                    productActiveService.updateStep(logVO);
                }
            case 1:
                try {
                    int lease = 0;
                    String tenantId = null;
                    String startTime = null;
                    for (Object order1 : orders) {
                        // 判断用户的产品id
                        Map<String, Object> order = (Map<String, Object>) order1;
                        if (order.get("productId").equals(productActiveProperties.getAppBuziId())) {
                            lease = Integer.valueOf(String.valueOf(order.get("lease")));
                            tenantId = String.valueOf(order.get("kaiInstanceId"));
                            startTime = String.valueOf(order.get("start_time"));
                            break;
                        }
                    }
                    if (lease > 0) {
                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        Date start = format.parse(startTime);
                        EffectBuziInfoVO effectInfo = licenseQuery.queryEffectUserOfTenant(tenantId, start);
                        Date effectStart = effectInfo.getActiveDate();
                        Calendar cal = Calendar.getInstance();
                        cal.setTime(start);
                        cal.add(Calendar.MONTH, lease);
                        // 续费人数也是生效日期
                        int maxUserCountOfTenant = licenseQuery.getMaxUserCountOfTenant(tenantId, new Date());
                        writeTenantTimeAndCount(tenantId, effectStart, cal.getTime(), maxUserCountOfTenant);
                    }
                    logVO.setStep(2);
                    productActiveService.updateStep(logVO);
                } catch (Exception e) {
                    logVO.setFailedStep(StringUtils.trimToEmpty(logVO.getFailedStep()) + "2,");
                    logVO.setStep(2);
                    productActiveService.updateStep(logVO);
                }
        }
    }

    private List<ActiveInfoVO> transActiveInfoVOS(List<Object> orders) {
        List<ActiveInfoVO> infos = new ArrayList<>(orders.size());
        for (Object data : orders) {
            Map<String, Object> order = (Map<String, Object>) data;
            ActiveInfoVO info = new ActiveInfoVO();
            info.setSkuId(String.valueOf(order.get("skuId")));
            info.setProductId(String.valueOf(order.get("productId")));
            info.setOrderCId(String.valueOf(order.get("orderCId")));
            info.setLease(Integer.valueOf(String.valueOf(order.get("skuId"))));
            info.setAccountQuantity(Integer.valueOf(String.valueOf(order.get("accountQuantity"))));
            info.setLease(Integer.valueOf(String.valueOf(order.get("lease"))));
            info.setAction(String.valueOf(order.get("action")));
            info.setCompanyName(String.valueOf(order.get("companyName")));
            info.setCompanyShortName(String.valueOf(order.get("companyShortName")));
            info.setEmail(String.valueOf(order.get("email")));
            info.setFromtype(Integer.valueOf(String.valueOf(order.get("fromtype"))));
            info.setKaiInstanceId(String.valueOf(order.get("kaiInstanceId")));
            info.setMobile(String.valueOf(order.get("mobile")));
            info.setOrderBizId(String.valueOf(order.get("orderBizId")));
            info.setOrderId(String.valueOf(order.get("orderId")));
            info.setProductName(String.valueOf(order.get("productName")));
            info.setYonyouUid(String.valueOf(order.get("yonyouUid")));
            info.setStart_time(String.valueOf(order.get("start_time")));
            infos.add(info);
        }
        return infos;
    }

}
